home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12860 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: unixg.ubc.ca!news
  2. From: jamesdf@unixg.ubc.ca (James Fairweather)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Can anyone HELP with variable delaration? Please?
  5. Date: Wed, 03 Apr 1996 05:57:05 GMT
  6. Organization: University of British Columbia
  7. Message-ID: <3162119a.43634755@news.ucs.ubc.ca>
  8. References: <4jt07b$dul@news.us.net>
  9. NNTP-Posting-Host: srtb0411a01.resnet.ubc.ca
  10. X-Newsreader: Forte Agent .99d/32.182
  11.  
  12. >I've just started learning C programming (moving up from Pascal) and I can't 
  13. >seem to find an answer to this question.  I'm sure this is going to sound 
  14. >stupid, but how can I declare a variable to be of a data type string?  Is 
  15. >there a data type "string"?
  16.  
  17. No there isn't.  Instead, we use arrays of characters to make a
  18. string.  
  19.  
  20. So you can write
  21.  
  22. char s[] = "Hello, World!";
  23. or 
  24. char s[20];
  25. strcpy(s, "Hi yourself.");
  26.  
  27. Also, any C++ development suite will have a String class, which will
  28. provide some functionality similar to Pascal's strings.
  29.  
  30. Here's a little hint about C, though: avoid strings like Ebola!  Only
  31. use strings when it's really necessary to use strings; otherwise use
  32. constants or integers.
  33. ---
  34. James Fairweather
  35. 4th year Comp. Eng, UBC
  36. Vancouver, BC, Canada
  37. jamesdf@unixg.ubc.ca
  38. 604.228.2269
  39.